package com.atguigu.lease.common.uitls;

import com.atguigu.lease.model.entity.BaseEntity;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName : getDate
 * Package: com.atguigu.lease.common.uitl
 * Description:
 *
 * @Author 李轩辕
 * @Create 6/4/2024 下午6:06
 * @Version 17.0
 */
public class DateUtil {
    public static Date getDate() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        String now = sdf.format(timestamp);
        Date date =sdf.parse(now);
        return date;
    }
    public  static void setDate(BaseEntity t)  {
        if (t.getId()!=0&&t.getId()!=null){
            try {
                t.setUpdateTime(DateUtil.getDate());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }else {
            try {
                t.setCreateTime(DateUtil.getDate());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
